home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12686 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: lori.albany.net!usenet
  2. From: sb0781@albany.net (Stephen Behnfeldt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Dynamically allocated interrupt handlers?
  5. Date: Thu, 21 Mar 1996 01:37:30 GMT
  6. Organization: AlbanyNet - E-mail info@albany.net
  7. Message-ID: <4iqbv5$mqd@lori.albany.net>
  8. NNTP-Posting-Host: pm3ip20-albny.albany.net
  9. X-Newsreader: Forte Free Agent v0.55
  10.  
  11. I am building a SerialPort class to model the serial ports on my PC.
  12. Associated with each instance of this class are elements such as an
  13. input character buffer and a hardware address - data members which
  14. will be unique to each instance.
  15.  
  16. I am also trying to code the interrupt handler which will be
  17. associated with this class.  While most of the code will be the same
  18. for each instance, the handler will have to know things like the
  19. hardware address and the location of the IO buffer for whichever port
  20. is generating the interrupt.  
  21.  
  22. I don't believe I can use a switch statement within the handler.  I
  23. can't write 
  24.     switch ( port ) { ... }
  25. to determine the instance-specific data, since the handler won't know
  26. which port generated the interrupt, unless that port can update a
  27. register or some global variable, which it could only do from within
  28. the handler, right?  So it seems like each handler will have to be
  29. distinct - one for each instance of the class.
  30.  
  31. Now, since I only have two serial ports, I could individually code two
  32. handlers, initializing each one with the appropriate values at the
  33. appropriate time - probably during the constructor or a member
  34. function fo the form SerialPort::Open( ).
  35.  
  36. However, it got me to wondering....
  37.  
  38. If I were writing a similar class for other hardware of an
  39. indeterminate number, is it possible to dynamically allocate the
  40. handler?  I could (theoretically) either use malloc( ), or somehow
  41. define the class to have distinct code for the handler.  I have been
  42. playing around with the static keyword, but so far to no avail.
  43.  
  44. Is this sort of situation common?  I couldn't find an answer in the
  45. c.l.c FAQ list; I couldn't locate the C++ FAQ list on the Web; and I
  46. haven't been able to FTP the FAQ list from MIT, evidently because my
  47. PC barfs when WS_FTP tries to download a file whose name includes "+".
  48.  
  49.  
  50. TIA,
  51.  
  52.  
  53. --spb
  54.  
  55.  
  56.